#include<stdio.h>
#include<algorithm>
using namespace std;
int n,ans = 0;
int a[19];
bool h[19];
void dfs(int step=1,int sum=0){
    if(step>n){
        ans = max(ans,sum);
    }
    else{
        int t = sum;
        for(int i = step-1;i>0;i--){
            if(h[i]==1){
                if(a[i]==a[step]) t+=a[step];
            }   
        }
        h[step] = 1;
        dfs(step+1,t);
        t = sum;
        for(int i = step-1;i>0;i--){
            if(h[i]==0){
                if(a[i]==a[step]) t+=a[step];
            }   
        }
        h[step] = 0;
        dfs(step+1,t);
    }
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i = 1;i<=n;i++) scanf("%d",&a[i]);
        dfs();
        printf("%d\n",ans);
        ans = 0;
    }
}